package com.directorio.modelo.dao;

import com.directorio.modelo.bean.Administrador;
import com.directorio.modelo.bean.Alumno;
import com.directorio.modelo.bean.Alumno_Capacitacion;
import com.directorio.modelo.bean.Alumno_Experiencia;
import com.directorio.modelo.bean.Alumno_Formacion;
import com.directorio.modelo.bean.Alumno_Habilidad;
import com.directorio.modelo.bean.Alumno_Requerimiento;
import com.directorio.modelo.bean.Dato_Tipo;
import com.directorio.modelo.dao.AlumnoDao;
import java.util.*;
import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;

public class AlumnoDaoImpl extends SqlMapClientDaoSupport implements AlumnoDao
{

    public AlumnoDaoImpl()
    {
    }

    public Alumno getAlumno(String codigo) throws Exception{
        Map<String, String> map = new HashMap<String, String>();
        map.put("cod_unp", codigo);
        Alumno alumno = (Alumno)getSqlMapClientTemplate().queryForObject("alumnoNS.getAlumnoIbt", map);
        return alumno;
    }
    public List<Alumno> getAllAlumno(Map<?, ?> map) throws Exception{
    	List<Alumno> list = null;
        try{
			List<Alumno> queryForList = (List<Alumno>)this.getSqlMapClientTemplate().queryForList("alumnoNS.getAllAlumnoIbt",map);
			list = queryForList;
        }catch(Exception ex){
        	ex.printStackTrace();
        	return null;
        }
        return list;
    }

    public Dato_Tipo validaLogin(String cod, String pwd)  throws Exception{
        Map<String, String> map = new HashMap<String, String>();
        map.put("cod", cod);
        map.put("pwd", pwd);
        return (Dato_Tipo)getSqlMapClientTemplate().queryForList("alumnoNS.validaLoginIbt", map).get(0);
    }
    public int insertAlumnoExperence(Alumno_Experiencia exper) throws Exception{
    	int ret = 0;
        try{
           ret = ((Integer)getSqlMapClientTemplate().queryForObject("alumnoNS.insertExperienciaIbt", exper)).intValue();
        }catch(Exception ex){
        	ex.printStackTrace();
        }
        return ret;
    }
    public int insertAlumnoCapacity(Alumno_Capacitacion capac) throws Exception{
    	int ret = 0;
        try{
           ret = ((Integer)getSqlMapClientTemplate().queryForObject("alumnoNS.insertCapacitacIbt", capac)).intValue();
        }catch(Exception ex){
        	ex.printStackTrace();
        }
        return ret;
    }
    public int insertAlumnoHabilidad(Alumno_Habilidad habil) throws Exception{
    	int ret = 0;
        try{
           ret = ((Integer)getSqlMapClientTemplate().queryForObject("alumnoNS.insertHabilIbt", habil)).intValue();
        }catch(Exception ex){
        	ex.printStackTrace();
        }
        return ret;
    }
    public int insertAlumnoFormacion(Alumno_Formacion formac) throws Exception{
    	int ret = 0;
        try{
           ret = ((Integer)getSqlMapClientTemplate().queryForObject("alumnoNS.insertFormacIbt", formac)).intValue();
        }catch(Exception ex){
        	ex.printStackTrace();
        }
        return ret;
    }
    public int insertAlumnoRequerimiento(Alumno_Requerimiento requerAlum) throws Exception{
    	int ret = 0;
        try{
           ret = ((Integer)getSqlMapClientTemplate().queryForObject("alumnoNS.insertAlumnRequerIbt", requerAlum)).intValue();
        }catch(Exception ex){
        	ex.printStackTrace();
        }
        return ret;
    }    
    public List<Alumno_Habilidad> getHabilidades(String cod_unp) throws Exception{
    	Map<String, String> map = new HashMap<String, String>();
    	map.put("_cod",cod_unp);
    	try{
    		return this.getSqlMapClientTemplate().queryForList("alumnoNS.getAlumnoHabilidadIbt",map);
    	}catch(Exception ex){
    		ex.printStackTrace();
    		return null;
    	}
    }
    public List<Alumno_Experiencia> getExperiencias(String cod_unp) throws Exception{
    	Map<String, String> map = new HashMap<String, String>();
    	map.put("cod_unp",cod_unp);
    	try{
    		return this.getSqlMapClientTemplate().queryForList("alumnoNS.getExperieciaIbt",map);
    	}catch(Exception ex){
    		ex.printStackTrace();
    		return null;
    	}
    }
    public List<Alumno_Capacitacion> getCapacitaciones(String cod_unp) throws Exception{
    	Map<String, String> map = new HashMap<String, String>();
    	map.put("cod_unp",cod_unp);
    	try{
    		return this.getSqlMapClientTemplate().queryForList("alumnoNS.getCapacitacIbt",map);
    	}catch(Exception ex){
    		ex.printStackTrace();
    		return null;
    	}
    }
    public int insertAdministrador(Administrador admin) throws Exception{
    	int ret = 0;
        try{
           ret = ((Integer)getSqlMapClientTemplate().queryForObject("alumnoNS.insertAdminIbt", admin)).intValue();
        }catch(Exception ex){
        	ex.printStackTrace();
        }
        return ret;
    }
    public Administrador getAdministrador(String codigo) throws Exception{
    	Administrador admin = null;
        Map<String, String> map = new HashMap<String, String>();
        map.put("cod", codigo);
        try{
        	admin = (Administrador)getSqlMapClientTemplate().queryForObject("alumnoNS.getAdministradorIbt", map);
        }catch(Exception ex){
        	ex.printStackTrace();
        }
    	return admin;
    }
    public Dato_Tipo updatePassword(Map map)  throws Exception{
    	try{
    		return (Dato_Tipo)getSqlMapClientTemplate().queryForList("alumnoNS.updatePwdIbt", map).get(0);
    	}catch(Exception ex){
    		ex.printStackTrace();
    		return null;
    	}
        
    }
    public int updateDatosAlumno(Map map)throws Exception {
		int ret = 0;
        try{
            ret = ((Integer)getSqlMapClientTemplate().queryForObject("alumnoNS.updateDatoAlumnIbt", map)).intValue();
        }catch(Exception ex){
            ex.printStackTrace();
        }
        return ret;
	}
    public List<Alumno_Formacion> getFormaciones(Map map){
    	try{
    		return this.getSqlMapClientTemplate().queryForList("alumnoNS.getAlumnFormacIbt", map);
    	}catch(Exception ex){
    		ex.printStackTrace();
    		return null;
    	}
    }
    public Dato_Tipo insertAlumno(Alumno alum){
    	try{
    		return (Dato_Tipo)this.getSqlMapClientTemplate().queryForObject("alumnoNS.insertAlumnIbt", alum);
    	}catch(Exception ex){
    		ex.printStackTrace();
    		return null;
    	}
    }
	
	public String getCantidadesAdminInfor(Map<?, ?> map) throws Exception{
		try{
    		return (String)this.getSqlMapClientTemplate().queryForObject("alumnoNS.getCantidadesAdminInformIbt",map);
    	}catch(Exception ex){
    		ex.printStackTrace();
    		return null;
    	}
	}
	public String getRequestUser(Map map) throws Exception{
		try{
    		return (String)this.getSqlMapClientTemplate().queryForObject("alumnoNS.aceptaRequetUserIbt",map);
    	}catch(Exception ex){
    		ex.printStackTrace();
    		return null;
    	}
	}
	public String delRequestUser(Map map) throws Exception{
		try{
    		return (String)this.getSqlMapClientTemplate().queryForObject("alumnoNS.eliminarRequetUserIbt",map);
    	}catch(Exception ex){
    		ex.printStackTrace();
    		return null;
    	}
	}	
	public int insertHabilidadAdministrador(Map map) throws Exception{
    	int ret = 0;
        try{
           ret = ((Integer)getSqlMapClientTemplate().queryForObject("alumnoNS.insertHabilAdminIbt", map)).intValue();
        }catch(Exception ex){
        	ex.printStackTrace();
        }
        return ret;
    }	
}